# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=openimageio
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.8.11
pkgrel=1
pkgdesc="A library for reading and writing images, including classes, utilities, and applications (mingw-w64)"
arch=('any')
url="http://www.openimageio.org/"
license=("custom")
depends=("${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-field3d"
         "${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-jasper"
         "${MINGW_PACKAGE_PREFIX}-giflib"
         "${MINGW_PACKAGE_PREFIX}-glew"
         "${MINGW_PACKAGE_PREFIX}-hdf5"
         "${MINGW_PACKAGE_PREFIX}-libjpeg"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-LibRaw"
         "${MINGW_PACKAGE_PREFIX}-libwebp"
         "${MINGW_PACKAGE_PREFIX}-libtiff"
         "${MINGW_PACKAGE_PREFIX}-opencolorio"
         "${MINGW_PACKAGE_PREFIX}-opencv"
         "${MINGW_PACKAGE_PREFIX}-openexr"
         "${MINGW_PACKAGE_PREFIX}-openjpeg"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-pugixml"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             #"${MINGW_PACKAGE_PREFIX}-qt5"
             "${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-boost")
optdepends=(#"${MINGW_PACKAGE_PREFIX}-qt4: iv image viewer"
            "${MINGW_PACKAGE_PREFIX}-python2: bindings support")
options=('strip' 'buildflags')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/OpenImageIO/oiio/archive/Release-${pkgver}.tar.gz
        0000-fix-mingw-w64.patch
        0000-workaround-ansidecl-h-PTR-define-conflict.patch
        0001-MinGW-w64-include-winbase-h-early-for-TCHAR-types.patch
        0003-boost-latest.patch
        0004-guard-msvc-stuff.patch
        0006-fix-intrinistic-conflict.patch
        0007-find-pugixml.patch
        0008-find-openjpeg.patch
        0009-msvcrt-dont-have-create-locale.patch)
sha256sums=('5a4d4a5480569d94bcaf759d1afa729881c90a2c1a30a5603c278d74ed0cae7e'
            '4787e771dbb9b794d47672a08fad3dbb0e36ac30e5c1058684437323b8238b37'
            'ab6bde02c0c05495a9cb13441535d42f4d5929bd930859d75f589d12be9a182b'
            'b7cc78d0f535ceb1aba68b11970c32ffbf04815d229b12e64e2c2c0b3403b4b2'
            'd6cc0ddc30e484978a89bdd8e30bbe4dee7c82f178721e571d35991b361994cf'
            '3a73e95486a5a50685eed753f11c433bcf9f1b1a46947d6ae1350c8f68568536'
            'ced593b71fab9db63fc692173dfd7625c6812d18e5a6a69e872a746e0857358c'
            'b5db09ae6931dde76b94f09ce53b1684260a928d0af5920ae54520975b69d6d8'
            'c644153bd6dbca0eff5b70c0bc3241faae0eb90f1bb0cf1f502bb0553a73223e'
            'd765b49b3671e9354776e33d68fc53e88c15b2c430e592a5aeae066d02a5b0da')

prepare() {
  cd ${srcdir}/oiio-Release-${pkgver}
  patch -p1 -i ${srcdir}/0000-fix-mingw-w64.patch
  patch -p1 -i ${srcdir}/0000-workaround-ansidecl-h-PTR-define-conflict.patch
  patch -p1 -i ${srcdir}/0001-MinGW-w64-include-winbase-h-early-for-TCHAR-types.patch
  patch -p1 -i ${srcdir}/0003-boost-latest.patch
  patch -p1 -i ${srcdir}/0004-guard-msvc-stuff.patch
  patch -p1 -i ${srcdir}/0006-fix-intrinistic-conflict.patch
  patch -p1 -i ${srcdir}/0007-find-pugixml.patch
  patch -p1 -i ${srcdir}/0008-find-openjpeg.patch
  patch -p1 -i ${srcdir}/0009-msvcrt-dont-have-create-locale.patch
}

build() {
  [[ -d "build-${MINGW_CHOST}" ]] && rm -rf "build-${MINGW_CHOST}"
  mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DUSE_FREETYPE=ON \
    -DUSE_OPENCV=ON \
    -DUSE_FIELD3D=ON \
    -DUSE_OPENSSL=ON \
    -DUSE_EXTERNAL_PUGIXML=ON \
    -DCMAKE_SHARED_LINKER_FLAGS=" -Wl,--export-all-symbols -Wl,--enable-auto-import " \
    -DOIIO_BUILD_TESTS=ON \
    ../oiio-Release-${pkgver}

  make
}

package() {
  cd "${srcdir}"/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install
  install -Dm644 ${srcdir}/oiio-Release-${pkgver}/LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
